<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            position: relative;
        }
        
        .head,
        .banner,
        .content,
        .footer {
            margin: 0 auto
        }
        
        .head {
            width: 1000px;
            height: 200px;
            background-color: antiquewhite;
        }
        
        .banner {
            width: 1000px;
            height: 200px;
            background-color: aquamarine;
        }
        
        .content {
            width: 1000px;
            height: 600px;
            background-color: blueviolet;
        }
        
        .footer {
            width: 1000px;
            height: 200px;
            background-color: brown;
        }
        
        .aside {
            position: absolute;
            width: 30px;
            height: 100px;
            background-color: pink;
            top: 300px;
            right: 90px
        }
        
        .goback {
            display: none;
        }
    </style>
</head>

<body>
    <div class="head">head区域</div>
    <div class="banner">banner区域</div>
    <div class="content">content区域</div>
    <div class="footer">footer区域</div>
    <div class="aside">
        <span class="goback">回到顶部</span>
    </div>
    <script>
        var aside = document.querySelector('.aside');
        var banner = document.querySelector('.banner');
        var content = document.querySelector('.content');
        var goback = document.querySelector('.goback');
        var bannertop = banner.offsetTop;
        var asidetop = aside.offsetTop - bannertop;
        document.addEventListener('scroll', function() {
            if (window.pageYOffset >= 200) {
                aside.style.position = 'fixed';
                aside.style.top = asidetop + 'px';
            } else {
                aside.style.position = 'absolute';
                aside.style.top = '300px';
            };
            if (window.pageYOffset >= 1000) {
                goback.style.display = 'block';
            } else {
                goback.style.display = 'none';
            }
        })
    </script>
</body>

</html>